import 'package:dio/dio.dart';
import 'package:jyofservice/bean/fee_list_entity.dart';
import 'package:jyofservice/util/webconfig.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

class FeeInfoPage extends StatefulWidget {
  String? ybbm;
  FeeInfoPage({this.ybbm});
  @override
  _FeeInfoPageState createState() => _FeeInfoPageState();
}

class _FeeInfoPageState extends State<FeeInfoPage> {

  List<FeeListEntity?> feeList = [];
  bool isloading = false;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getFeeData();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('收费记录'),
        centerTitle: true,
      ),
      body:Stack(
        alignment: Alignment(0.5, 0.5),
        children: [
          feeList.length == 0
              ? Container(

              child: Center(
                child: Image.asset("images/nodata.png"),
              )):
          Container(child:  ListView.builder(
                itemBuilder: (context, item) {
                  return buildListData(context, item);
                },
                itemCount: feeList.length,
              ),),
          Offstage(
            offstage: isloading,
            child: SpinKitFadingCircle(
              color: Colors.blue,
              size: 50.0,
            ),
          )
        ],
      )
    );
  }

  Widget buildListData(BuildContext context, int item) {
    return GestureDetector(
      onTap: (){

      },
      child:Container(
        margin: EdgeInsets.fromLTRB(5, 5,5, 5),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(10)),
        ),
        width: ScreenUtil().screenWidth,
        height: ScreenUtil().setHeight(300),
        child: Row(
          children: <Widget>[
            Container(
              decoration: BoxDecoration(
                color: Colors.blue,
                borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(10),
                    bottomLeft: Radius.circular(10)),
              ),
              width: ScreenUtil().setWidth(10),
            ),
            Expanded(
              flex: 1,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Padding(
                    padding: EdgeInsets.only(left: 5),
                    child: Text(
                      '收费编码：' + feeList[item]!.clientCode.toString() ?? "",
                      style: TextStyle(
                          fontSize: ScreenUtil().setSp(32),
                          color: Colors.black87),
                    ),
                  ),
                  Padding(
                      padding: EdgeInsets.only(left: 5),
                      child: Row(
                        children: <Widget>[
                          Expanded(
                            child: Text(
                              '收费时间：' + feeList[item]!.sfDt! ?? "",
                              style: TextStyle(
                                  fontSize: ScreenUtil().setSp(32),
                                  color: Colors.black87),
                            ),
                          ),
                        ],
                      )),
                  Container(
                    width: ScreenUtil().screenWidth,
                    height: ScreenUtil().setHeight(2),
                    color: Colors.grey,
                  ),
                  SizedBox(
                    height: ScreenUtil().setHeight(10),
                  ),
                  Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Expanded(
                          flex: 1,
                          child: Center(
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: <Widget>[
                                Text('交费年度',style: TextStyle(
                                    color: Colors.blue,
                                    fontSize: ScreenUtil().setSp(40))),
                                SizedBox(
                                  height: ScreenUtil().setHeight(20),
                                ),
                                Text(
                                  feeList[item]!.feeYear.toString() ?? "",
                                )
                              ],
                            ),
                          )),
                      Expanded(
                          flex: 1,
                          child:Center(
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: <Widget>[
                                Text('交费方式',style: TextStyle(
                                    color: Colors.blue,
                                    fontSize: ScreenUtil().setSp(40))),
                                SizedBox(
                                  height: ScreenUtil().setHeight(20),
                                ),
                                Text(
                                  feeList[item]!.jffs.toString() ?? "",
                                )
                              ],
                            ),
                          )),
                      Expanded(
                          flex: 1,
                          child: Center(
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: <Widget>[
                                Text('实收¥',style: TextStyle(
                                    color: Colors.blue,
                                    fontSize: ScreenUtil().setSp(40))),
                                SizedBox(
                                  height: ScreenUtil().setHeight(20),
                                ),
                                Text(
                                  feeList[item]!.ss.toString() ?? "",
                                )
                              ],
                            ),
                          )),
                    ],
                  ),
                ],
              ),
            )
          ],
        ),
      ) ,
    );
  }

  Future getFeeData() async{
    feeList.clear();
    try {

      Response response = await Dio().get(
        WebConfig().jichaUrl + "method=get_fee_info&ybbm="+widget.ybbm!,);
      print(response.data.toString());

      for (int i = 0; i < response.data.length; i++) {
        FeeListEntity? dyListEntity = FeeListEntity().fromJson(response.data[i]);
        feeList.add(dyListEntity);
      }
      if(mounted) {
        setState(() {
          isloading = true;
        });
      }

      return response.data;
    } catch (e) {
      print(e.toString());
    }
  }
}
